package com.sunny.ynhz.ui.index;

import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.jauker.widget.BadgeView;
import com.sunny.ynhz.R;
import com.sunny.ynhz.ui.MainActivity;
import com.sunny.ynhz.ui.ynts.WxyyActivity;
import com.sunny.ynhz.ui.ynts.partorlstaticfragment.RiverStaticActivity;
import com.sunny.ynhz.ui.login.LoginActivity;
import com.sunny.ynhz.ui.base.BaseFragment;
import com.sunny.ynhz.ui.daily.indexproblem.HistoryActivity;
import com.sunny.ynhz.ui.daily.indexproblem.MyRiverActivity;
import com.sunny.ynhz.ui.login.PrivateRuleActivity;
import com.sunny.ynhz.ui.mine.AboutActivity;
import com.sunny.ynhz.ui.mine.AccountSetActivity;
import com.sunny.ynhz.ui.mine.JuniorRiverChiefsActivity;
import com.sunny.ynhz.ui.mine.MineActivity;
import com.sunny.ynhz.ui.mine.ScoreExchangeActivity;
import com.sunny.ynhz.ui.ynts.TestMoreLineActivity;
import com.sunny.ynhz.ui.ynts.problemover.ProblemStaticActivity;
import com.sunny.ynhz.ui.ynts.problemover.TownsProblemStaticFragment;
import com.sunny.ynhz.utils.AlertUtils;
import com.sunny.ynhz.utils.AppManager;
import com.sunny.ynhz.utils.SPUtil;
import com.sunny.ynhz.utils.SettingUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/12/012.
 */

public class MineFragment extends BaseFragment {
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.level)
    TextView level;
    private AlertUtils alertUtils;
    private MainActivity mainActivity;


    public static MineFragment getInstanceMineFragment() {
        return new MineFragment();
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void setUpView() {
        super.setUpView();
        alertUtils = new AlertUtils();
        mainActivity = (MainActivity) activity;
        BadgeView badgeView = new BadgeView(getActivity());
        badgeView.setBadgeGravity(Gravity.RIGHT | Gravity.TOP);
        badgeView.setBadgeCount(6);
        if (!SPUtil.get("name", "null").equals("null")) {
            name.setText(SPUtil.get("name", "null").toString());
        }
        level.setText(SPUtil.get("roleNames", "").toString());
    }

    @Override
    protected void init() {
        super.init();
    }

    @OnClick({R.id.rl_legal_notice, R.id.ll_jd, R.id.junior_riverchiefs, R.id.exit, R.id.my_patrol, R.id.my_river, R.id.account_set, R.id.about, R.id.permission_setting, R.id.score_exchange})
    public void onClick(View view) {
        if (view.getId() == R.id.ll_jd) {
            doActivity(MineActivity.class);
        } else if (view.getId() == R.id.junior_riverchiefs) {
            doActivity(JuniorRiverChiefsActivity.class);
        } else if (view.getId() == R.id.exit) {
            if (mainActivity != null && mainActivity.newPatrolFragment != null && mainActivity.newPatrolFragment.isPatrolling()) {
                alertUtils.setTitle("提示");
                alertUtils.setMsg("您当前巡河未结束，为了保证系统能正常记录你的巡河轨迹，请结束巡河后再进行退出");
                alertUtils.setEnsureButton("结束巡河");
                alertUtils.setNegativeButton("退出");
                alertUtils.displayDiago(activity, new AlertUtils.IClickButton() {
                    @Override
                    public void ensure() {
                        mainActivity.newPatrolFragment.stopCurrentPatrol();
                        alertUtils.closeDialog();
                    }

                    @Override
                    public void cancel() {
                        SPUtil.put("username","");
                        doActivity(LoginActivity.class);
                        AppManager.getInstance().finishActivity(MainActivity.class);
                    }
                });
            } else {
                SPUtil.put("username","");
                doActivity(LoginActivity.class);
                AppManager.getInstance().finishActivity(MainActivity.class);
            }
        } else if (view.getId() == R.id.my_patrol) {
            doActivity(HistoryActivity.class);
        } else if (view.getId() == R.id.my_river) {
            doActivity(MyRiverActivity.class);
        } else if (view.getId() == R.id.account_set) {
            doActivity(AccountSetActivity.class);
        } else if (view.getId() == R.id.about) {
            doActivity(AboutActivity.class);
        } else if (view.getId() == R.id.permission_setting) {
//            SystemIntentUtils.gotoPermissionSetting(activity);
            SettingUtils.enterWhiteListSetting(activity);
        } else if (view.getId() == R.id.score_exchange) {//积分兑换
            doActivity(ScoreExchangeActivity.class);
        } else if (view.getId() == R.id.rl_legal_notice) {
            doActivity(PrivateRuleActivity.class);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }
}
